﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using x.paypal.service;
using x.paypal.model;
using System.Configuration;

namespace SampleSite
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            IPayPalAdaptivePaymentService _paysvc = new PayPalAdaptivePaymentService();
            Uri redirectUrl = new Uri(ConfigurationManager.AppSettings["REDIRECT-URL"]); 
            Uri returnUrl = new Uri(ConfigurationManager.AppSettings["PAYPAL-RETURNURI"]);
            Uri cancelUrl = new Uri(ConfigurationManager.AppSettings["PAYPAL-CANCELURI"]);
            string seller = ConfigurationManager.AppSettings["PAYPAL-SELLER"];
            string paymentref = "test123";
            string currency = "USD"; 
            List<Receiver> receivers = new List<Receiver>();
            receivers.Add(new Receiver { Amount = "10", Email = seller, InvoiceId = paymentref, Description = "test paypal payment" });
            IPayRequest payRequest = new PayRequest().CreateRequest().WithPaymentReference(paymentref).WithReturnUri(returnUrl).WithCancelUri(cancelUrl).Currency(currency).ReceiverList(receivers);
            var resp = _paysvc.RequestPayment(payRequest);
            lblPayKey.Text = resp.PayKey; 
            Response.Redirect("https://www.sandbox.paypal.com/us/cgi-bin/webscr?cmd=_ap-payment&paykey="+resp.PayKey); 
        }
    }
}
